package com.vote.web.controller.business;

import com.vote.business.domain.vo.FrontUserVoteStatusTotalVO;
import com.vote.business.domain.vo.FrontUserVoteTotalVO;
import com.vote.business.service.IFrontUserVoteTotalService;
import com.vote.common.core.domain.AjaxResult;
import com.vote.common.core.domain.entity.SysUser;
import com.vote.common.core.domain.model.LoginUser;
import com.vote.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/business/frontUserVoteRecord")

public class FrontUserVoteStatController {

    @Autowired
    IFrontUserVoteTotalService frontUserVoteTotalService;

    @GetMapping("/countVotesByUserId")
    public AjaxResult getCountVotesByUserId() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        FrontUserVoteTotalVO frontUserVoteTotalVO = frontUserVoteTotalService.countVotesByUserId(user.getUserId());
        return AjaxResult.success(frontUserVoteTotalVO);
    }
    @GetMapping("/countVotesStatusByUserId/{status}")
    public AjaxResult getCountVotesStatusByUserId(@PathVariable Long status) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        FrontUserVoteStatusTotalVO frontUserVoteStatusTotalVO=new FrontUserVoteStatusTotalVO();
        frontUserVoteStatusTotalVO.setUserId(user.getUserId());
        frontUserVoteStatusTotalVO.setStatus(status);
        FrontUserVoteStatusTotalVO result = frontUserVoteTotalService.countStatusVotesByUserId(frontUserVoteStatusTotalVO);
        return AjaxResult.success(result);
    }

}
